﻿using IDAdmin.Lib.DataLayer;
using Quartz;
using Quartz.Impl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace IDAdmin.Common
{
    public class JobScheduler
    {
        //static IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
        IScheduler scheduler;
        //List<string> gameServerList = new List<string>();
        public JobScheduler()
        {
            //gameServerList = WebDB_N.ListServer().Select(s => s.tablezone).ToList();
            scheduler = StdSchedulerFactory.GetDefaultScheduler();
            scheduler.Start();
        }
        public void startInsertGoldSave()
        {
            IJobDetail job = JobBuilder.Create<GoldSaveJob>().Build();

            ITrigger trigger = TriggerBuilder.Create().WithIdentity("startInsertGoldSave").WithCronSchedule("0 0 6 1/1 * ? *").StartNow().Build();

            scheduler.ScheduleJob(job, trigger);
        }

        public void startInsertScoredCardSave()
        {
            IJobDetail job = JobBuilder.Create<ScoredCardSaveJob>().Build();

            ITrigger trigger = TriggerBuilder.Create().WithIdentity("startInsertScoredCardSave").WithCronSchedule("0 0 6 1/1 * ? *").StartNow().Build();

            scheduler.ScheduleJob(job, trigger);
        }

        public void startTranferLevelVN()
        {
            
            IJobDetail job = JobBuilder.Create<TransferLevelVN>().Build();

            ITrigger trigger = TriggerBuilder.Create().WithIdentity("TransferLevelVN").WithCronSchedule("0 0 9 1/1 * ? *").StartNow().Build();
            
            scheduler.ScheduleJob(job, trigger);
        }

        public void startTranferFilledCard()
        {
            IJobDetail job = JobBuilder.Create<TransferFilledCard>().Build();

            ITrigger trigger = TriggerBuilder.Create().WithIdentity("TransferFilledCard").WithCronSchedule("0 0 5 1/1 * ? *").StartNow().Build();

            scheduler.ScheduleJob(job, trigger);
        }
        public void startCronPremiumLogin()
        {
            IJobDetail job = JobBuilder.Create<CronPremiumLogin>().Build();

            ITrigger trigger = TriggerBuilder.Create().WithIdentity("CronPremiumLogin").WithCronSchedule("0 0 7 1/1 * ? *").StartNow().Build();

            scheduler.ScheduleJob(job, trigger);
        }

        public void startCronLoginNewSave()
        {
            IJobDetail job = JobBuilder.Create<CronLoginNewSave>().Build();

            ITrigger trigger = TriggerBuilder.Create().WithIdentity("CronLoginNewSave").WithCronSchedule("0 0 7 1/1 * ? *").StartNow().Build();

            scheduler.ScheduleJob(job, trigger);
        }
        // sửa lại 12h 3 method tiếp theo, tạm thời để 2h
        public void startCronLevelDis()
        {
            IJobDetail job = JobBuilder.Create<CronLevelDis>().Build();

            ITrigger trigger = TriggerBuilder.Create().WithIdentity("CronLevelDis").WithCronSchedule("0 0 12 1/1 * ? *").StartNow().Build();

            scheduler.ScheduleJob(job, trigger);
        }

        public void startCronLevelLoss()
        {
            IJobDetail job = JobBuilder.Create<CronLevelLoss>().Build();

            ITrigger trigger = TriggerBuilder.Create().WithIdentity("CronLevelLoss").WithCronSchedule("0 0 12 1/1 * ? *").StartNow().Build();

            scheduler.ScheduleJob(job, trigger);
        }

        public void startCronLevelSave()
        {
            IJobDetail job = JobBuilder.Create<CronLevelSave>().Build();

            ITrigger trigger = TriggerBuilder.Create().WithIdentity("CronLevelSave").WithCronSchedule("0 0 12 1/1 * ? *").StartNow().Build();

            scheduler.ScheduleJob(job, trigger);
        }
    }
}